home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / PredatorPrey / FlightSim / mouseMove.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-22  |  4.3 KB  |  188 lines  |  [TEXT/KAHL]

  1. #include "flight.h"
  2.  
  3.  
  4. extern    FxVector    fxGrid[GRID_SZ][GRID_SZ];
  5. extern    FxVector    fxGridRot[GRID_SZ][GRID_SZ];
  6. extern    FxVector    fxOriginV;
  7.  
  8. extern    FracThreeMatrx    fracRotatMatrx;
  9. extern    FxThreeMatrx    transpCurrFxRotMatrx;
  10.  
  11. extern    Fract    sinPtOne, cosPtOne, sinPtTwo, cosPtTwo;
  12. extern    Fract    sinNPtOne, cosNPtOne, sinNPtTwo, cosNPtTwo;
  13.  
  14. extern    WindowPtr        theWind;    /*the main window*/
  15.  
  16.  
  17. FxVector    pyramid    = {iToFix(-200), iToFix(-100), iToFix(25)},
  18.             cpyPyramid    = {iToFix(-200), iToFix(-100), iToFix(25)};
  19.  
  20. DoMouseMove(strtClik)
  21. Point    *strtClik;
  22. {
  23. static    int        lookUp[6][6] = 
  24.     {    11,    11,    16,    16,    15,    15,
  25.         11,    12,    13,    13,    14,    15,
  26.         6,    7,    8,    8,    9,    10,
  27.         6,    7,    8,    8,    9,    10,
  28.         0,    3,    4,    4,    5,    2,
  29.         0,    0,    1,    1,    2,    2};
  30.  
  31.     int        hCoord, vCoord;
  32.     Point    clikPt;
  33.  
  34.     clikPt = *strtClik;
  35.  
  36.     while (StillDown())
  37.     {
  38.         hCoord = clikPt.h / 43;
  39.         vCoord = clikPt.v / 43;
  40.  
  41.         SetBack();
  42.         DoMove(lookUp[vCoord][hCoord]);
  43.         GetWind(theWind);
  44.         SetPort(theWind);
  45.         GetMouse(&clikPt);
  46.     }
  47. }
  48.  
  49. DoMove(posCoord)
  50. int        posCoord;
  51. {
  52.  
  53.     register    int    i, j;
  54.     FxVector    tempV, _fxGrid[GRID_SZ][GRID_SZ];
  55.     Point    clikPt;
  56.     FxThreeMatrx    currFxRotMatrx;
  57. static    FxVector    xIncrmnt = {iToFix(stepSize), 0, 0};
  58.  
  59.     switch    (posCoord) {
  60.     case 0:
  61.         FracYRotatMatrx(cosPtTwo, sinPtTwo, fracRotatMatrx);
  62.         FracXRotatMatrx(cosPtTwo, sinPtTwo, fracRotatMatrx);
  63.         break;
  64.     case 1:
  65.         FracYRotatMatrx(cosPtTwo, sinPtTwo, fracRotatMatrx);
  66.         break;
  67.     case 2:
  68.         FracYRotatMatrx(cosPtTwo, sinPtTwo, fracRotatMatrx);
  69.         FracXRotatMatrx(cosNPtTwo, sinNPtTwo, fracRotatMatrx);
  70.         break;
  71.     case 3:
  72.         FracYRotatMatrx(cosPtOne, sinPtOne, fracRotatMatrx);
  73.         FracXRotatMatrx(cosPtOne, sinPtOne, fracRotatMatrx);
  74.         break;
  75.     case 4:
  76.         FracYRotatMatrx(cosPtOne, sinPtOne, fracRotatMatrx);
  77.         break;
  78.     case 5:
  79.         FracYRotatMatrx(cosPtOne, sinPtOne, fracRotatMatrx);
  80.         FracXRotatMatrx(cosNPtOne, sinNPtOne, fracRotatMatrx);
  81.         break;
  82.     case 6:
  83.         FracXRotatMatrx(cosPtTwo, sinPtTwo, fracRotatMatrx);
  84.         break;
  85.     case 7:
  86.         FracXRotatMatrx(cosPtOne, sinPtOne, fracRotatMatrx);
  87.         break;
  88.     case 8:
  89.         DoForward();
  90.         break;
  91.     case 9:
  92.         FracXRotatMatrx(cosNPtOne, sinNPtOne, fracRotatMatrx);
  93.         break;
  94.     case 10:
  95.         FracXRotatMatrx(cosNPtTwo, sinNPtTwo, fracRotatMatrx);
  96.         break;
  97.     case 11:
  98.         FracYRotatMatrx(cosNPtTwo, sinNPtTwo, fracRotatMatrx);
  99.         FracXRotatMatrx(cosPtTwo, sinPtTwo, fracRotatMatrx);
  100.         break;
  101.     case 12:
  102.         FracYRotatMatrx(cosNPtOne, sinNPtOne, fracRotatMatrx);
  103.         FracXRotatMatrx(cosPtOne, sinPtOne, fracRotatMatrx);
  104.         break;
  105.     case 13:
  106.         FracYRotatMatrx(cosNPtOne, sinNPtOne, fracRotatMatrx);
  107.         break;
  108.     case 14:
  109.         FracXRotatMatrx(cosNPtOne, sinNPtOne, fracRotatMatrx);
  110.         break;
  111.     case 15:
  112.         FracXRotatMatrx(cosNPtTwo, sinNPtTwo, fracRotatMatrx);
  113.         break;
  114.     case 16:
  115.         FracYRotatMatrx(cosNPtTwo, sinNPtTwo, fracRotatMatrx);
  116.         break;
  117.     }
  118.  
  119.     if (posCoord NEQ 8)
  120.     {
  121.         FractToFixMatrx(fracRotatMatrx, currFxRotMatrx);
  122.         FxTranspMatrx(currFxRotMatrx, transpCurrFxRotMatrx);
  123.         DoStep();
  124.  
  125.         for (i = 0; i < GRID_SZ; i++)
  126.         {
  127.             for (j = 0; j < GRID_SZ; j++)
  128.             {
  129.                 FxSubtVector(&fxGrid[i][j], &fxOriginV, &tempV);
  130.                 FxMatrxMul(currFxRotMatrx, &tempV, &_fxGrid[i][j]);
  131.             }
  132.         }
  133.         FxSubtVector(&pyramid, &fxOriginV, &tempV);
  134.         FxMatrxMul(currFxRotMatrx, &tempV, &cpyPyramid);
  135.  
  136.         EraseRect(&thePort->portRect);
  137.         for (i = 0; i < GRID_SZ; i++)
  138.         {
  139.             FxPlotLine(&_fxGrid[i][0], &_fxGrid[i][GRID_SZ - 1]);
  140.         }
  141.         for (j = 0; j < GRID_SZ; j++)
  142.         {
  143.             FxPlotLine(&_fxGrid[0][j], &_fxGrid[GRID_SZ - 1][j]);
  144.         }
  145.         *(FxGridMatrx *)fxGridRot = *(FxGridMatrx *)_fxGrid;    
  146.         DrawPyr();
  147.     }
  148. }
  149.  
  150. DoStep()
  151. {
  152. static    FxVector    xIncrmnt = {iToFix(stepSize), 0, 0};
  153.     FxVector    tempV;
  154.  
  155.     FxMatrxMul(transpCurrFxRotMatrx, &xIncrmnt, &tempV);
  156.     FxSubtVector(&fxOriginV, &tempV, &fxOriginV);
  157. }
  158.  
  159. DoForward()
  160. {
  161.     FxVector    tempV;
  162.     register    int    i, j;
  163. static    FxVector    xIncrmnt = {iToFix(stepSize), 0, 0};
  164.  
  165.     FxMatrxMul(transpCurrFxRotMatrx, &xIncrmnt, &tempV);
  166.     FxSubtVector(&fxOriginV, &tempV, &fxOriginV);
  167.     for (i = 0; i < GRID_SZ; i++)
  168.         for (j = 0; j < GRID_SZ; j++)
  169.             fxGridRot[i][j].x += iToFix(stepSize);
  170. cpyPyramid.x += iToFix(stepSize);
  171.  
  172.     EraseRect(&thePort->portRect);
  173.     for (i = 0; i < GRID_SZ; i++)
  174.         FxPlotLine(&fxGridRot[i][0], &fxGridRot[i][GRID_SZ - 1]);
  175.  
  176.     for (j = 0; j < GRID_SZ; j++)
  177.         FxPlotLine(&fxGridRot[0][j], &fxGridRot[GRID_SZ - 1][j]);
  178. DrawPyr();
  179. }
  180.  
  181. DrawPyr()
  182. {
  183.     FxPlotLine(&fxGridRot[0][0], &cpyPyramid);
  184.     FxPlotLine(&fxGridRot[1][0], &cpyPyramid);
  185.     FxPlotLine(&fxGridRot[0][1], &cpyPyramid);
  186.     FxPlotLine(&fxGridRot[1][1], &cpyPyramid);
  187. }
  188.